package can;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;

import netclient.Client;

/*
 * Requests:
 * Annotate
 * Log in
 * Search
 * Upload
 * XDS-Submit
 * 
 * All of these methods accept the cleaned up parameters from their respective beans, and return
 * the result string to be displayed on the form;
 * 
 */

public class RequestHandler {
	public static InputStream resultStream;
	
	public static String annotate(String document) {
		ExampleToolClass exampleWorker = new ExampleToolClass();
		exampleWorker.stuff();
		return "result";
	}
	
	public static String logIn() {
		return "result";
	}
	
	public static String search(String query, String list) {
		//parse list of options
		String got = Client.sendMessage("search:"+query);
		
		return got;
	}
	
	public static String[] getParams() {
		Client.sendMessage("getParams");
		
		String results = "";
		Scanner sc = new Scanner(resultStream);
		if (sc.hasNextLine()) results = sc.nextLine();
		
		byte[] res = results.getBytes();
		int size = 0;
		
		for (int i=0; i<res.length; i++) {
			if (res[i] == ',' || res[i] == ':') size ++;
		}
		
		String[] out = new String[size];
		
		int outPlace = 0;
		for (int i=0; i<res.length; i++) {
			if (res[i] == ',' || res[i] == ':') {
				for (int n=i+1; n<res.length; n++) {
					if (res[n] == ',') break;
					else out[outPlace] += i;
				}
				outPlace ++;
			}
		}
		return out;
	}
	
	public static String upload() {
		return "result";
	}
	
	public static String xdsSubmit() {
		return "result";
	}
}
 